package inabit.utils;

import inabit.data.Rule;
/**Substitutes the tags at the rule string form
 * by specific values
 * @author Rafael Rocha*/
public class RuleStringFormat {
	private ExpressionStringFormat format;
	private String ifStr;
	private String thenStr;
	
	public RuleStringFormat(){
		format = new ExpressionStringFormat();
		ifStr = "if";
		thenStr = "then";
	}
	
	public void setIfString(String ifStr) {
		this.ifStr = ifStr;
	}
	public void setThenString(String thenStr) {
		this.thenStr = thenStr;
	}
	public void setExpressionFormat(ExpressionStringFormat expFormat) {
		this.format = expFormat;
	}
	public void setFormat(ExpressionStringFormat expFormat, String ifStr, String thenStr) {
		this.format = expFormat;
		this.ifStr = ifStr;
		this.thenStr = thenStr;
	}
	public String getString(Rule rule) {
		return rule.getID() + " : " + formatBodyString(rule.getBodyDescription());
	}
	public String getID(String ruleString) {
		return ruleString.split(":")[0].trim();
	}
	public String formatBodyString(String ruleStr) {
		ruleStr = format.formatString(ruleStr);
		ruleStr = ruleStr.replaceAll("<if>", ifStr);
		ruleStr = ruleStr.replaceAll("<then>", thenStr);
		return ruleStr;
	}
	
	public ExpressionStringFormat getExpressionFormat() {
		return format;
	}
	public String getIfString() {
		return ifStr;
	}
	public String getThenString() {
		return thenStr;
	}
}
